
 //1.编程题：https://bigfrontend.dev/zh/problem/implement-Promise-allSettled
 const allSettled = (promises) => {
    return new Promise((resolve, reject) => {
        if (!Array.isArray(promises)) {
            return reject(new TypeError("argument must be an array"))
        }
        var countNum = 0;
        var promiseNum = promises.length;
        var resolvedvalue = [];
        for (let i = 0; i < promiseNum; i++) {
            if (!promises[i] instanceof Promise) {
                return reject(new TypeError("argument must be a Promise"))
            }
            Promise.resolve(promises[i])
                .then(value => {
                    countNum++;
                    resolvedvalue[i] = { status: 'fulfilled', value };
                    if (countNum === promiseNum) {
                        return resolve(resolvedvalue)
                    }
                }, reason => {
                    countNum++;
                    resolvedvalue[i] = { status: 'rejected', reason };
                    if (countNum === promiseNum) {
                        return resolve(resolvedvalue)
                    }
                })
        }
    })
}

//2.算法题：https://leetcode-cn.com/problems/design-a-stack-with-increment-operation/
//#### 1381. 设计一个支持增量操作的栈
/**
 * @param {number} maxSize
 */
var CustomStack = function (maxSize) {
    this.list = [];
    this.maxSize = maxSize
};

/** 
 * @param {number} x
 * @return {void}
 */
CustomStack.prototype.push = function (x) {
    if (this.list.length < this.maxSize)
        this.list.push(x)
};

/**
 * @return {number}
 */
CustomStack.prototype.pop = function () {
    if (this.list.length === 0) return -1
    const temp = this.list[this.list.length - 1]
    this.list.length = this.list.length - 1
    return temp
};

/** 
 * @param {number} k 
 * @param {number} val
 * @return {void}
 */
CustomStack.prototype.increment = function (k, val) {
    for (let i = 0; i < this.list.length && i < k; i++) {
        this.list[i] += val
    }
};

/**
 * Your CustomStack object will be instantiated and called as such:
 * var obj = new CustomStack(maxSize)
 * obj.push(x)
 * var param_2 = obj.pop()
 * obj.increment(k,val)
 */

